#include <iostream>
using namespace std;
const int N = 1010;
int n, q;
int a[N][N];
int b[100001];
void test1() {
    for (int i = 1; i <= n / 2; i++) {
        for (int j = 1; j <= n; j++) {
            int x = n + 1 - i, y = n + 1 - j;
            swap(a[i][j], a[x][y]);
        }
    }
    if (n % 2 != 0) {
        int i = n / 2 + 1;
        for (int j = 1; j <= n / 2; j++) {
            swap(a[i][j], a[i][n - j + 1]);
        }
    }
}
void test2() {
    for (int i = 1; i <= n / 2; i++) {
        for (int j = 1; j <= n; j++) {
            swap(a[i][j], a[n - i + 1][j]);
        }
    }
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    cin >> q;
    int row = 0, col = 0;
    for (int i = 1; i <= q; i++) {
        cin >> b[i];
        if (b[i] == 1) {
            col++;
        } else {
            row++;
        }
    }
    if (col % 2) test1();
    if (row % 2) test2();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}